package com.road.vast.service;

import com.road.vast.component.JwtTokenComponent;
import com.road.vast.pojo.Login;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author 郭泽鹏
 * @Date 2020/7/30 13:47
 * @Version 1.0
 * @Description 登录授权服务类
 */
@Service
public class LoginService {
    @Autowired
    JwtTokenComponent jwtToken;

    public String login(Login login, String password) {
        //生成jwt信息
        Map<String, Object> map = new HashMap<>();

        //向Token中存数据
        map.put("companyId", login.getCompanyId());
        map.put("companyName", login.getCompanyName());
        System.out.println("*******key=" + jwtToken.getJwtUtils().getKey());
        System.out.println("*******ttl=" + jwtToken.getJwtUtils().getTtl());
        String token = jwtToken.getJwtUtils().createJWT(login.getId(), login.getUsername(), map);
        return token;
    }

}
